package com.ultrawise.survey.module.surevybase.dao;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.ultrawise.survey.core.Page;
import com.ultrawise.survey.core.PaginationHelper;
import com.ultrawise.survey.core.base.BaseDao;
import com.ultrawise.survey.module.surevybase.vo.TSurveyDataTotal;

@Repository("tSurveyDataTotalDAO")
public class TSurveyDataTotalDAO extends BaseDao {

	
	public Page<TSurveyDataTotal> getTsurveTotalpage(TSurveyDataTotal dto, int pageNo, int pageSize) {
		PaginationHelper<TSurveyDataTotal> ph = new PaginationHelper<TSurveyDataTotal>();
		String sql = " from " + dto.getTableName() + " where 1=1";
		Object[] params = new Object[7];
		int index = 0;
		if (!StringUtils.isEmpty(dto.getSy_id())) {
			sql += " and SY_ID =  ? ";
			params[index] =  dto.getSy_id();
			index++;
		}
		sql +=" group by qn_id,qn_choose";
		Object[] paramsEnd = new Object[index];
		System.arraycopy(params, 0, paramsEnd, 0, index);

		return ph.fetchPage(getJdbcTemplate(), "select count(*) " + sql,
				"select * " + sql, paramsEnd, pageNo, pageSize,
				new BeanPropertyRowMapper<TSurveyDataTotal>(TSurveyDataTotal.class));
	}
}
